{extend name="public/base"/} {block name="body"}
<style>
    .mui-row.mui-fullscreen>[class*="mui-col-"] {
        height: 100%;
    }

    .mui-col-xs-3,
    .mui-col-xs-9 {
        overflow-y: auto;
        height: 100%;
    }

    .mui-segmented-control .mui-control-item {
        line-height: 50px;
        width: 100%;
    }

    .mui-control-content {
        display: block;
    }

    .mui-segmented-control.mui-segmented-control-inverted .mui-control-item.mui-active {
        background-color: #fff;
    }
    .mui-toast-container {
        bottom: 50%;
        z-index: 999999999999999999;
    }
    .mui-btn-block{
      padding: 5px;
      border: 1px solid #ccc !important;
      margin: 5px;
      -webkit-appearance: none;
    }
    .active .mui-icon{
      display: block !important;
    }
    .submitbuttonqx {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 2.876712rem;
        background-color: red;
        color: #fff;
        text-align: center;
        text-decoration: none;
        font-size: 0.410959rem;
        font-weight: bold;
        line-height: 1.315068rem;
    }
</style>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/xsd/css/checkout.css" />
<header class="mui-bar mui-bar-nav" style="z-index:7">
			<a class="mui-icon mui-icon-left-nav mui-pull-left" href="{:url('index/index/qiye', ['cid'=>$cid ])}" ></a>
			<h1 class="mui-title">确定订单:</h1>
</header>
<div class="mui-content" style="    margin-bottom:60px;">

  <section class="cart-address" >
    {empty name="$qiyeUserinfo"}
    <div class="address-item" onclick='window.location.href = "{:url('index/address/addqiye', ['cid'=>$cid ])}"' > 请添加一个用户信息 <span class="mui-icon mui-icon-arrowright"></span> </div><input type="hidden" value="11" id="testid" />
    {else /}
    <div class="address-item"   onclick='window.location.href =  "{:url('index/address/qiyeindex', ['cid'=>$cid ])}"'   >
        <h2 class="address-name" > <b >{$qiyeUserinfo.username}</b>  <span >{$qiyeUserinfo.phone}</span> </h2>
        <span class="mui-icon mui-icon-arrowright"></span>  </div>
    {/empty}


  </section>


  <section class="cart-group checkout-section">
    <h4 style="padding: .2rem .4rem;color: #666;    margin-bottom: 0;">商品列表</h4>
    <ul class="foodlist" style="    margin: 0;">
        {volist name="cartinfo.list" id="vo"}
          <li> <span class="cellname">{$vo.good_name}</span> <span class="cellquantity">x&nbsp;{$vo.num}</span> <span class="celltotal">¥{$vo['num']*$vo['good_price']}</span> </li>
        {/volist}
    </ul>

    <div class="total">
        <div> <span>总计 <span id="zj" style="color:red">¥{$cartCountprice}</span>
          {eq name="$companyInfo['is_wxpay']" value="1" }
            余额 ¥{$Request.session.user.balance}</span> &nbsp;&nbsp;
          {/eq}
         </div>
<span>实付<span style="color:red;" id="sf" data-sf="{$cartCountprice+$address.freight-$Request.session.user.balance}"> ¥{$cartCountprice+$address.freight-$Request.session.user.balance}</span></span>
      </div>
  </section>
  <section class="checkout-section">
    <div class="cart-item fee" id="pstime" style="    margin: 0;" >
      <span>配送时间</span>
       <span class="cartitem-right" id="pssj">
         <i style="    font-style: normal;">
              {$companyInfo['delivery_dec']}
         </i>
       </span>
    </div>
    <div class="cart-item fee" id="payment" style="    margin: 0;">
      <span>支付方式</span>
      <span class="cartitem-right">
        <i id="paywaytext" style="    font-style: normal;">
        {eq name="$companyInfo['is_wxpay']" value="1" }
          微信支付
        {else /}
          货到付款
        {/eq}

        </i>
        <span class="mui-icon mui-icon-arrowright"></span>
      </span>
    </div>
    <!-- <aside class="paylist ">
        <header class="paylist-header">支付方式</header>

        {eq name="$companyInfo['is_wxpay']" value="1" }
          <div class="paylist-item  {eq name='Think.cookie.pay' value='1'}active{/eq}" data-payway='1' ><span> 微信支付  </span> <span class="mui-icon mui-icon-checkmarkempty" style="color:#007aff;border: 1px solid;display:none"></span></div>
        {/eq}
        <div class="paylist-item  {eq name='Think.cookie.pay' value='2'}active{/eq}" data-payway='2' ><span> 货到付款  </span> <span class="mui-icon mui-icon-checkmarkempty" style="color:#007aff;border: 1px solid;display:none"></span></div>
    </aside>
    <div class="mask "></div> -->
    {eq name="$companyInfo['is_wxpay']" value="1" }
      <a class="cart-item fee"  id="coupon-item" style="    margin: 0;"> <span>优惠券</span>
        <span class="cartitem-right">
          <i style="    font-style: normal;">
            {empty name="Think.cookie.couponlist_id"}
              请选择优惠券
            {else /}
              {$Think.cookie.couponlist_id|get_table_field="id","price","CouponList"}元优惠券
            {/empty}
          </i>
          <span class="mui-icon mui-icon-arrowright"></span>
        </span>
      </a>
    {/eq}
  </section>


  <form  method="post"  action="{:url('order/qiye', ['cid'=>$cid ])}">
    <section class="checkout-section">
    <div class="mui-input-row" style="margin: 10px 5px;">
      <textarea id="textarea" name="remark" rows="5" placeholder="备注"></textarea>
    </div>
    </section>
    <input type="hidden" name="index_type" value="1"  />
    <input type="hidden" name="is_tg" value="1"  />
    <input type="hidden" name="group_time" value="{:config('grouptime')}"  />
  </form>

  <script id="tpl2" type="text/html">
        <div class="select-time-box">
          <style>.wd50{width:50%!important;}</style>
          {literal}
          {{if date1}}

            <dl class="wd50"  id="jtdd"> <dt>{{date1}}<span>{{name1}}</span></dt>
                {{each list as value i}}
                  <dd class="allow"   data-start="{{value.start_time}}"  data-text="{{date1}}{{value.start_time}}-{{value.end_time}}送达" data-val="{{date1}},{{value.start_time}}-{{value.end_time}}">
                  	 <label for="radio-choice-0">{{value.start_time}}-{{value.end_time}}</label> </dd>
                {{/each}}
            </dl>
            {{else}}
              <style>.wd50{width:100%!important;}</style>
            {{/if}}
           {/literal}

 {literal}
            <dl  class="wd50"> <dt>{{date2}}<span>{{name2}}</span></dt>
            	 {{if type2==2}}

            	<dd class="allow" data-text="{{date2}}10:00-13:00送达" data-val="{{date2}},10:00-13:00">
                  	<label for="radio-choice-0">10:30-13:00</label> </dd>
                  	{{/if}}
                {{each list as value i}}
                  <dd class="allow" data-text="{{date2}}{{value.start_time}}-{{value.end_time}}送达" data-val="{{date2}},{{value.start_time}}-{{value.end_time}}">
                  	<label for="radio-choice-0">{{value.start_time}}-{{value.end_time}} </label> </dd>
                {{/each}}
            </dl>
            {/literal}
        </div>
  </script>


  <div class="select-time-mask" onclick="hideDeliveryTime()" style="display: none;"></div>
  <div class="select-time-wrap" id="select-model-01" style="display: none;"></div>

  <nav class="mui-bar mui-bar-tab" style="   border-bottom: none;  background-color: #3d3d3f; ">
      <span style="    color: #fff;font-size: .48rem;line-height: 1.273333rem;padding-left: .266667rem;">待支付 <span id="dzf" style="color:red"></span></span>
      <a href="javascript:" class="submitbutton" style="right: 2.876712rem;" >确定下单</a>
      <a  class="submitbuttonqx qxdd" data-url="{:url('index/qiye', ['cid'=>$cid ])}" >取消订单</a>
  </nav>
</div>

{/block}
{block name="script"}
<script type="text/javascript">
  $(function(){
    $('.submitbutton').on('tap', function(){        	if($("#testid").val()==11){    		   mui.toast('请添加用户！');        return;    	}
      $('form').submit();
    })

    $('#coupon-item').on('tap', function(){
        window.location.href = "{:url('index/coupon/index')}"
    })

    var is_wxpay = "{$companyInfo['is_wxpay']}"

    if(is_wxpay  == 1){
      changeprice(is_wxpay)
    }



    $('.qxdd').on('tap', function(){
     var url = $(this).attr('data-url')
     var btnArray = ['否', '是'];
     mui.confirm('您确定要删除该订单吗？', '删除订单', btnArray, function(e) {
       if (e.index == 1) {
           $.post("{:url('index/cart/clear')}", {}, function(data) {
               mui.toast('删除成功！')
               setTimeout(function() {
                 window.location.href= url
               }, 2000);
           }, "json");

       } else {
         return ;
       }
     })

    })

    // $('#pstime').on('tap', function(){
    //           $(".select-time-mask").show(), $(".select-time-wrap").show();
    //
    // })
    $(document).on('tap', '.select-time-box dd.allow',function(){
      var $this = $(this),text = $this.attr('data-text'),val = $this.attr('data-val')
        $('#pssj i').text(text)
        $('#pssj input').val(val)
        $(".select-time-wrap").hide(), $(".select-time-mask").hide()

        $.getJSON("{:url('index/cart/changecookie')}", {name: 'deliverytime', 'val': val}, function(json, textStatus) {
   		 });
    })

    $('#payment').on('tap', function(){
        $('.paylist').addClass('open');
        $('.paylist').next().addClass('open');
    })

    $('.mask').on('tap', function(){
      $(this).removeClass('open')
      $('.paylist').removeClass('open')
    })
    $('.paylist-item').on('tap', function(){
      var val = $(this).text(),payway = $(this).attr('data-payway')
      $('#paywaytext').text(val)
      $('.paylist').next().removeClass('open')
      $('.paylist').removeClass('open')
      $(this).addClass('active').siblings().removeClass('active')
      $.getJSON("{:url('index/cart/changecookie')}", {name: 'pay', 'val': payway}, function(json, textStatus) {});
    })

  })

  function hideDeliveryTime() {
      $(".select-time-mask").hide(), $(".select-time-wrap").hide()
  }
  showDeliveryTime()
function showDeliveryTime() {
    var data = {}
        data.jt = new Date(),
        data.jm = data.jt.getMonth()+1,
        data.jd = data.jt.getDate();
        data.rq = data.jm+'-'+data.jd;

    $.post("{:url('index/index/getDeliveryTime')}", function(da) {
        if(da){
          data.list = da;

             data.name1 = ""

            data.date1 = ''

        }

        data.list = [{id: 10, start_time: "明天", end_time: "18:00", limit_num: 10, type: 0},{id: 11, start_time: "后天", end_time: "22:00", limit_num: 10, type: 0}]
          // data.name2 = "{:config('grouptime')} 配送"
          var html = template('tpl2', data);
          $('.select-time-wrap').html(html);



    }, "json");

}

function changeprice(way_id){
  if(way_id==1){
    $('.fbt').text("-¥{$subsidy}")
    $('#freight').text("¥{$address.freight|default='0'}")
    $('#zj').text("¥{$cartCountprice+$address.freight}");
    $('#sf').text("¥{$cartCountprice+$address.freight-$Request.session.user.balance}");
    preferential("{$cartCountprice+$address.freight-$Request.session.user.balance}")
    $('#zt_address').hide();
  }else{
      //除去运费、运费补贴、计算总价
      $('#freight').text('¥0')
      $('.fbt').text('-¥0')
      $('#zj').text("¥{$cartCountprice}");
      $('#sf').text("¥{$cartCountprice-$Request.session.user.balance}");
      preferential("{$cartCountprice-$Request.session.user.balance}")


      $('#zt_address').show();
  }
}



function  preferential(sf){
  var yhj = "{$Think.cookie.couponlist_id|get_table_field="id","price","CouponList"}"
  if(yhj){
    var dzf =sf-parseInt(yhj)
  }else{
    dzf =sf

    yhj = 0
  }
  dzf = parseFloat(dzf).toFixed(2)


  $('#dzf').text('¥'+dzf)

  if(sf<0){
    var ye = parseFloat("{$Request.session.user.balance}")+parseFloat(sf)-parseFloat(yhj)
    ye = ye.toFixed(2)
    $('#sf').text('余额支付'+ye)
    $('#dzf').text('余额支付'+ye)

    $('#paywaytext').text('余额支付')
    $('.paylist').remove();
  }

}

</script>
{/block}
